<?php
$public = [];
$v1 =  [
    //首页相关接口
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/home', 'pluralize' => false,
        'extraPatterns' => [
            'GET app' => 'app',   //获取APP升级地址
            'GET home' => 'home',   //获得首页信息-app
            'GET home-v2' => 'home-v2',   //获得首页信息-app
            'GET home-trade' => 'home-trade',   //获得首页信息-app
            'GET hello' => 'hello',   //获得首页信息-app
            'GET sms' => 'sms',     //微信CODE
            'POST upload' => 'upload',
            'GET about' => 'about',
            'GET test' => 'test',
            //客服信息
            'GET service' => 'service',
            'GET config' => 'config',

            //兴趣信息
            'GET config-interest' => 'config-interests',
        ]
    ],

    //网站图片相关接口
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/images', 'pluralize' => false,
        'extraPatterns' => [
            'GET images' => 'images',           //获取图片
        ]
    ],

    // 验证码
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/sms', 'pluralize' => false,
        'extraPatterns' => [
            'PUT login-code' => 'login-code',
            'PUT register-code' => 'register-code',
            'PUT forget-code' => 'forget-code',
            'PUT modify-password-code' => 'modify-password-code',
            'PUT pay-code' => 'pay-code',
            'PUT place-code' => 'place-code',
            'PUT money-switch-code' => 'money-switch-code',
        ]
    ],

    //用户账号
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/account', 'pluralize' => false,
        'extraPatterns' => [
            'GET captcha' => 'captcha',
            'POST register' => 'register',
            'POST in-pass' => 'in-pass',
            'POST in-code' => 'in-code',
            'POST forget' => 'forget',
            'POST modify-password' => 'modify-password',
            'POST pay-password' => 'pay-password',
            'GET out' => 'out',
        ]
    ],

    //用户相关接口
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/user', 'pluralize' => false,
        'extraPatterns' => [
            "GET sig" => "sig",
            "GET,POST info" => "info",
            "GET level-info" => "level-info",
            "POST list" => "list",
            "GET tx-info" => "tx-info",
            "POST send-business-card" => "send-business-card", //发送名片

            //kyc认证
            'GET,POST kyc' => 'kyc',


            'POST follow' => 'follow',      //关注
            'DELETE follow' => 'follow',      //取消关注
            'GET interest-list' => 'interest-list',     //推荐列表
            'GET attention-list' => 'attention-list',     //关注和粉丝列表

            //注销
            'DELETE cancellation' => 'cancellation',
            
            //打招呼
            "GET,POST greet" => "greet",
            "GET receive-greet" => "receive-greet",
            "POST can-greet" => "can-greet",

            // 附近的人
            "GET nearby" => "nearby",

            'GET view-list' => 'view-list',     //看我的列表
            //商户
            "GET,POST business" => "business",

        ]
    ],

    //用户实名认证
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/kyc', 'pluralize' => false,
        'extraPatterns' => [
            'GET,POST auth' => 'auth',
        ]
    ],

    //文章管理
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/article', 'pluralize' => false,
        'extraPatterns' => [
            'GET info' => 'info',     //文章信息
        ]
    ],

    //============================== IM接口相关开始 ==============================
    // imFriend
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/friend', 'pluralize' => false,
        'extraPatterns' => [
            # 好友申请
            'GET apply-list' => 'apply-list',
            'POST apply' => 'apply',
            'POST apply-check' => 'apply-check',

            # 好友关系
            'GET list' => 'list',
            'GET,DELETE info' => 'info',
            'POST update-mark' => 'update-mark',
        ]
    ],


    // group
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/group', 'pluralize' => false,
        'extraPatterns' => [
            # 群申请
            'POST apply' => 'apply',
            'GET apply-list' => 'apply-list',
            'POST apply-check' => 'apply-check',

            # 群管理
            'POST create' => 'create',
            'GET list' => 'list',
            'GET,POST,DELETE info' => 'info',
            'GET group-user-num' => 'group-user-num',
            'POST trans' => 'trans',
            'POST shut-up' => 'shut-up',
            'POST set-manage' => 'set-manage',

            # 群成员
            'GET user-list' => 'user-list',
            'GET user-info' => 'user-info',
            'POST update-business-card' => 'update-business-card',
            'POST update-red-packet-state' => 'update-red-packet-state',
            'POST user-shut-up' => 'user-shut-up',
            'POST,DELETE user-quit-group' => 'user-quit-group',
            'POST invite-friend' => 'invite-friend',
        ]
    ],

    // 红包管理
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/red-packet', 'pluralize' => false,
        'extraPatterns' => [
            'POST send' => 'send',
            'POST receive' => 'receive',
            'GET state' => 'state',
            'GET receive-list' => 'receive-list',
            'GET log-list' => 'log-list',
        ]
    ],

    // 转账管理
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/transfer', 'pluralize' => false,
        'extraPatterns' => [
            'POST,GET transfer' => 'transfer',
        ]
    ],

    //============================== IM接口相关结束 ==============================



    //============================== 商城接口相关开始 ==============================
    //商品相关API
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/goods', 'pluralize' => false,
        'extraPatterns' => [
            //商品栏目相关
            'GET category-list' => 'category-list', #全部分类

            //商品相关
            'GET goods-list' => 'goods-list',
            'GET info' => 'info',
            'GET goods-collection' => 'goods-collection',
            'GET goods-collect-list' => 'goods-collect-list',

            //评论
            'GET comment-list' => 'comment-list',
            'POST comment' => 'comment',
            'DELETE delete-comment' => 'delete-comment',
            'POST comment-like' => 'comment-like',     //点赞
            'GET goods-like' => 'goods-like',     //我想要

            //商户
            'GET,POST add-edit' => 'add-edit',                 //修改商品信息

            'GET goods-status' => 'goods-status',     //上下架
        ]
    ],

    //购物车相关
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/cart', 'pluralize' => false,
        'extraPatterns' => [
            'GET list' => 'list',
            'GET,POST,PUT,DELETE info' => 'info',
        ]
    ],

    //用户地址相关接口
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/address', 'pluralize' => false,
        'extraPatterns' => [
            'GET address' => 'address',

            'GET list' => 'list',
            'GET,POST default' => 'default',
            'POST,GET,DELETE info' => 'info',
        ]
    ],

    // 订单相关接口
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/goods-order', 'pluralize' => false,
        'extraPatterns' => [
            'POST preview-info' => 'preview-info',   #进入订单页时的数据
            'POST,GET info' => 'info',   //创建订单
            'POST pay' => 'pay',   //确认付款
            'POST cancel' => 'cancel',
            'POST order-receive' => 'order-receive',  //确认收货
            'POST apply-return' => 'apply-return',  //退款
            'POST extend-confirm' => 'extend-confirm',  //延迟收货

            'GET list' => 'list',   //获取订单列表
            'GET status' => 'status',   //获取订单信息

            //商户
            'GET business-list' => 'business-list',              //订单列表
            'GET business-info' => 'business-info',              //订单详情
            'POST deliver' => 'deliver',                        //发货
            'POST shop-cancel' => 'shop-cancel',                        //商户取消订单
            'POST return-info' => 'return-info',              //退款同意或驳回申请
            'GET express-list' => 'express-list',              //快递列表

            //查看物流
            'GET show-logistics' => 'show-logistics',
        ]
    ],

    //============================== 商城接口相关结束 ==============================

    //============================== 钱包管理 ==============================
    // 账务信息
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/user-fund', 'pluralize' => false,
        'extraPatterns' => [
            # 记录
            'GET,POST log' => 'log',
            # 钱包开关
            'POST money-switch' => 'money-switch',
        ]
    ],

    //充值
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/recharge', 'pluralize' => false,
        'extraPatterns' => [
            'GET config' => 'config',
            'POST recharge' => 'recharge',
            'GET list' => 'list',
        ]
    ],

    // 账户绑定信息
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/receipt', 'pluralize' => false,
        'extraPatterns' => [
            'GET,POST,DELETE bank' => 'bank',
            'GET bank-list' => 'bank-list',
        ]
    ],

    // 提现
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/withdraw', 'pluralize' => false,
        'extraPatterns' => [
            'POST order' => 'order',
            'GET config' => 'config',
            'GET history' => 'history',
        ]
    ],

    //============================== 圈子 ==============================
    // 圈子 circle
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/circle', 'pluralize' => false,
        'extraPatterns' => [
            # 圈子
            'POST info' => 'info',
            'GET info' => 'info',
            'GET config' => 'config',
            'GET list' => 'list',
            'DELETE delete' => 'delete',

            'POST like' => 'like',           # 圈子点赞
            'POST collect' => 'collect',           # 圈子收藏
            //置顶设置
            'GET circle-setting' => 'circle-setting',

            'POST comment' => 'comment',                    //评论圈子
            'DELETE delete-comment' => 'delete-comment',     //删除评论
            'POST comment-like' => 'comment-like',           # 评论点赞
            'GET comment-my' => 'comment-my',           # 评论和回复我的列表
            'GET relation-list' => 'relation-list',           # 收到的 点赞  收藏列表

            'GET comment-list' => 'comment-list',           # 评论

        ]
    ],

    //============================== 反馈 ==============================
    // 反馈
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/feedback', 'pluralize' => false,
        'extraPatterns' => [
            # 反馈
            'POST info' => 'info',
        ]
    ],

    // 举报
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/report', 'pluralize' => false,
        'extraPatterns' => [
            # 举报
            'GET category' => 'category',
            'POST info' => 'info',
        ]
    ],



    //============================== 礼物 ==============================
    // 礼物
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/gift', 'pluralize' => false,
        'extraPatterns' => [
            'GET category' => 'category',
            'GET list' => 'list',
            'POST send' => 'send',
            'GET receive-list' => 'receive-list',
        ]
    ],


    //版本
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/versions', 'pluralize' => false,
        'extraPatterns' => [
            'GET app' => 'app',
            'GET download' => 'download',
        ]
    ],

    //============================== 用户等级 ==============================
    // 级别
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/user-level', 'pluralize' => false,
        'extraPatterns' => [
            'GET list' => 'list',
            'GET,POST order' => 'order',
        ]
    ],

    //============================== 金币管理 ==============================
    // 金币
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/coin', 'pluralize' => false,
        'extraPatterns' => [
            'GET list' => 'list',
            'GET,POST order' => 'order',
        ]
    ],

    //============================== 回调 ==============================
    //回调
    [
        'class' => 'yii\rest\UrlRule', 'controller' => 'v1/notify', 'pluralize' => false,
        'extraPatterns' => [
            'POST alipay-notify' => 'alipay-notify',
        ]
    ],



];
$v2 = [

];
function addOptions($rules = []) {
    foreach ($rules as $k => $v) {
        if(! array_key_exists('OPTIONS <action>', $v['extraPatterns'])) {
            $rules[$k]['extraPatterns']['OPTIONS <action>'] = 'options';
        }
    }
    return $rules;
}
$rules = array_merge(addOptions($v1), addOptions($v2), $public);


return [
    "rules" => $rules
];
